package csm.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
public class IndexController {

    @RequestMapping({"/", "/index"})
    public ModelAndView index() {
        return new ModelAndView("index");
    }
    @RequestMapping(value = "/login",method = RequestMethod.POST)
    public String login(Model model,
                        @RequestParam(value = "username",required = false) String username,
                        @RequestParam(value = "password",required = false) String password,
                        HttpSession session) {
        model.addAttribute("username",username);
        model.addAttribute("password",password);
        return "index";
    }
//    @RequestMapping(value = "/login")
//    public String test(HttpServletRequest request,HttpSession session) {
//        String username = request.getParameter("username");
//        System.out.println(username);
//        return "index";
//    }
}
